﻿using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Mota.XMLControls
{
    /// <summary>
    /// Represent Numeric control based on DX SpinEdit 
    /// </summary>
    public class DXGuiNumeric:GuiNumeric

    {
        /// <summary>
        /// Create SpingEdit control
        /// </summary>
        public DXGuiNumeric()
        {
            
            visualControl = new SpinEdit();
            (visualControl as SpinEdit).EditValueChanged += DXGuiNumeric_EditValueChanged;
        }

        void DXGuiNumeric_EditValueChanged(object sender, System.EventArgs e)
        {
            this.ChangeEventCall(null);
        }
        /// <summary>
        /// GET|SET SpinEdit Text property
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as SpinEdit).Text;
            }
            set
            {
                (visualControl as SpinEdit).Text = value;
            }
        }

        /// <summary>
        /// GET|SET SpinEdit.Properties.MinValue property
        /// </summary>

        public override decimal Min
        {
            get
            {
                return (visualControl as SpinEdit).Properties.MinValue;
            }
            set
            {
                (visualControl as SpinEdit).Properties.MinValue = value;
            }
        }
        /// <summary>
        /// GET|SET SpingEdit.Properties.MaxValue property
        /// </summary>
        public override decimal Max
        {
            get
            {
                return (visualControl as SpinEdit).Properties.MaxValue;
            }
            set
            {
                (visualControl as SpinEdit).Properties.MaxValue = value;
            }
        }
        /// <summary>
        /// Add DataBinding to SpinEdit Value property
        /// </summary>
        /// <param name="valueBinding">main binding source with current record values</param>
        public override void SetValue(object valueBinding)
        {
            if(valueBinding is BindingSource)
                (visualControl as SpinEdit).DataBindings.Add("Value", valueBinding as BindingSource, XmlAttributes["XMLAttribute"], true);

        }
        /// <summary>
        /// Dummy property
        /// </summary>
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
               // throw new System.NotImplementedException();
            }
        }

        public override object GetValue()
        {
            return (visualControl as SpinEdit).Value;
        }
    }
}
